package com.lt.crm.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lt.crm.pojo.Storage;
import com.lt.crm.pojo.SysRole;
import com.lt.crm.service.StorageService;
import javax.annotation.Resource;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;



@Controller
@RequestMapping("/storage")
public class StorageController {
    @Resource
    StorageService storageService;

    @RequestMapping("/list")
    public String list(Model model,
                       @RequestParam(required = false, defaultValue = "1") Integer pageIndex,
                       @RequestParam(required = false, defaultValue = "") String stkWarehouse,
                       @RequestParam(required = false, defaultValue = "") String prodName) {
//        Sort sort = new Sort(Sort.Direction.ASC, "stkId");
//        Pageable pageable = PageRequest.of(pageIndex - 1, 3, sort);
    Page<Storage> page = new Page<>(pageIndex, 5);
      Page<Storage> storagePage = storageService.findAllByPage(page, stkWarehouse, prodName);
        model.addAttribute("storagePage", storagePage);
        model.addAttribute("stkWarehouse", stkWarehouse);
        model.addAttribute("prodName", prodName);
        return "storage/list";
    }
}
